package cn.zyzpp.service.job.impl;

import cn.zyzpp.dao.UserJobDao;
import cn.zyzpp.entity.job.UserJob;
import cn.zyzpp.service.job.UserJobService;
import cn.zyzpp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Create by yster@foxmail.com 2018/5/25/025 14:15
 */
@Service
@CacheConfig(cacheNames = {"UserJobService"})
public class UserJobServiceImpl implements UserJobService {
    @Autowired
    private UserJobDao userJobDao;

    @Override
    @CacheEvict(allEntries = true)
    public void save(UserJob userJob) {
        userJobDao.save(userJob);
    }



    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<UserJob> queryByUid(int uid) {
        return userJobDao.findAllByUid(uid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public int countByJid(int jid) {
        return userJobDao.countByJid(jid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public List<UserJob> queryByJid(int jid) {
        return userJobDao.findAllByJid(jid);
    }

    @Override
    @Cacheable(key = "targetClass + methodName +#p0")
    public UserJob queryByUidAndPid(int uid, int jid) {
        return userJobDao.findAllByUidAndJid(uid, jid);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void delectByUidAndJid(int uid, int jid) {
        userJobDao.deleteAllByUidAndJid(uid, jid);
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataJkByUidAndJid(int uid, int jid, String s) {
        UserJob userJob = userJobDao.findAllByUidAndJid(uid, jid);
        userJob.setJ_remark(StringUtil.symline(s));
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataUkByUidAndJid(int uid, int jid, String s) {
        UserJob userJob = userJobDao.findAllByUidAndJid(uid, jid);
        userJob.setU_remark(StringUtil.symline(s));
    }

    @Override
    @Transactional
    @CacheEvict(allEntries = true)
    public void updataUJSatate(int uid, int jid, String s) {
        UserJob userJob = userJobDao.findAllByUidAndJid(uid, jid);
        userJob.setState(s);
    }

}
